<?php

class productplace{
	
	function getPlaceByProductId($product_id){
		$placeList = array();
		qdbconn();
		$query = "select places.pla_name, propla_quantity
					FROM product_place
						JOIN places on product_place.propla_pla_id = places.pla_id
					WHERE propla_status = 1
					AND propla_pro_id = $product_id";
		$result = mysql_query($query);
		
		$i = 0;
		while ($row = mysql_fetch_row($result)) {
			$placeList[$i]['pla_name']				= $row[0];
			$placeList[$i]['pro_pla_quantity']		= $row[1];
			$i++;
		}
		
		return $placeList;
	}
	
	function getProductPlaceList(){
		$productplaceList = array();
		qdbconn();
		
		$query = "select propla_id,pla_name,pro_name,
					propla_quantity,  propla_status
					from products pr, product_place pp, places pl
					where propla_pro_id = pro_id and propla_pla_id=pla_id ";
		$result = mysql_query($query);
		
		$i = 0;
		while ($row = mysql_fetch_row($result)) {
			$productplaceList[$i]['propla_id']		= $row[0];
			$productplaceList[$i]['pla_name']		= $row[1];
			$productplaceList[$i]['pro_name']		= $row[2];
			$productplaceList[$i]['propla_quantity']= $row[3];
			$productplaceList[$i]['propla_status']	= $row[4];
			
			$i++;
		}
		
		return $productplaceList;
	}
	
	function insertAProductPlace($data){
		qdbconn();
		$propla_quantity 		= $data['propla_quantity'];
		$propla_pro_id		 	= $data['propla_pro_id'];
		$propla_pla_id	 		= $data['propla_pla_id'];
		//$propla_status			= $data['propla_status'];
		
		
		$query = "INSERT INTO product_place (propla_quantity, propla_pro_id,propla_pla_id) 
					values ($propla_quantity,$propla_pro_id,$propla_pla_id)";
				
				$result = mysql_query($query);
					return $result;
			
		}		
	
	
	function inactivateAProductPlace($propla_id){
		qdbconn();		
		$query = "UPDATE product_place SET propla_status = 0 where propla_id = $propla_id";
		//echo $query;die;
		$result = mysql_query($query);
		return $result;
	}
	
	function activateAProductPlace($propla_id){
		qdbconn();		
		$query = "UPDATE product_place SET propla_status = 1 where propla_id = $propla_id";
		$result = mysql_query($query);
		return $result;
	}
	
	function editAProductPlace($data){
		qdbconn();
		$propla_id				= $data['propla_id'];
		$propla_quantity 		= $data['propla_quantity'];
		$propla_pro_id		 	= $data['propla_pro_id'];
		$propla_pla_id	 		= $data['propla_pla_id'];
		
		$query = "UPDATE product_place SET propla_quantity=$propla_quantity, 
					propla_pro_id=$propla_pro_id, propla_pla_id=$propla_pla_id
						 WHERE propla_id = $propla_id";

		$result = mysql_query($query);
		
		return $result;
	}
	
	function getProductPlaceInfo($propla_id){
		qdbconn();		
		$query = "SELECT * FROM product_place
					WHERE propla_id = $propla_id";
		$result = mysql_query($query);
		$current_data = array();
		if ($row = mysql_fetch_row($result)) {
			$current_data['propla_id'] 			= $row[0];
			$current_data['propla_quantity'] 	= $row[1];
			$current_data['propla_pro_id'] 		= $row[2];
			$current_data['propla_pla_id'] 		= $row[3];
			$current_data['propla_status'] 		= $row[4];
			
		}
		return $current_data;
	
	}

}
?>